<?php 
// 查课接口设置
function getWk($type, $noun, $school, $user, $pass, $name = false){
	global $DB;
	global $wk;
	$a = $DB->get_row("select * from qingka_wangke_huoyuan where hid='{$type}' ");
	$type = $a["pt"];
	$cookie = $a["cookie"];
	$token = $a["token"];
	//27查课接口
	if ($type == "27") {
		$data = array("uid" => $a["user"], "key" => $a["pass"], "school" => $school, "user" => $user, "pass" => $pass, "platform" => $noun);
		$eq_rl = $a["url"];
		$er_url = "$eq_rl/api.php?act=get";
		$result = get_url($er_url, $data);
		$result = json_decode($result, true);
		return $result;
	}
	//自营ikun
	if ($type == "k") {
		$data = array("uid" => $a["user"], "key" => $a["pass"], "school" => $school, "user" => $user, "pass" => $pass, "platform" => $noun);
		$eq_rl = $a["url"];
		$er_url = "$eq_rl/api.php?act=get";
		$result = get_url($er_url, $data);
		$result = json_decode($result, true);
		return $result;
	}
	//shouji查课接口
	 else if ($type == "shouji") {
    $data = array("school" => $school, "username" => $user, "password" => $pass);
    $jz_surl = $a["url"];
    $jz_url = "$jz_surl/api/$noun";
    $result = get_url($jz_url, $data, $cookie);
    $result = json_decode($result, true);
    $code = $result["code"];
    $resultd = explode("\n", $result["data"]);

    // Check if $pass is a valid China mainland mobile phone number
  if (!preg_match('/^1[34578]\d{9}$/', $pass)) {
        $b = ["code" => -1, 'msg' => "填写的手机号真的正确吗？"];
    } else {
        $courseList = $resultd;
        $json_data = [];

        foreach ($courseList as $key => $value) {
            $value = '收货人的手机号';
            
            $json_data[] = [
                'id' => '联系方式'.$pass,
                'name' => '收件地址：'.$school,
            ];
        }

        $b = [
            'code' => 0,
            'msg' => '查询成功',
            'data' => $json_data
        ];
    }

    return $b;
}

	//wklm查课接口
	else if($type == "wklmcookie"){
       $data = array("ptid" => $noun, "school"=>$school, "studentnumber" => $user,"studentpwd" => $pass); 
       
       $wklm_surl = $a["url"];
       $wklm_url = "$wklm_surl/order/search";
       // 在后台设置接口里面填cookie
       $header = ["Cookie:$cookie"];
       $result = post($wklm_url, $data, $header); 
       
       $result = json_decode($result, true); 
    if ($result["code"] != 1 ) {
                        $b = ["code" => -1, 'msg' => "信息错误或者重试"];
                    }else{
                     $courseList = $result["data"]["courseList"]; 
                      
                     foreach ($courseList as $key => $value) {
                         
                         $json_data[] = [
                                'id' => "",
                                'name' => $value['name'],
                            ]; 
                             
                     }
                       $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ];  
                  
        }
  return $b;}
  //蛋蛋查课接口
	else if($type == "dandan"){
	   $accountmsg=["$school $user $pass"];
	   $data = array("accountmsg" =>$accountmsg , "value"=>$noun, "token" => $token); 
       $data=json_encode($data,true);
       $ll_surl = $a["url"];
       $ll_url = "$ll_surl/order/query/";
       $header = ["Content-Type:application/json;charset=UTF-8",];
       $result =post($ll_url,$data,$header); 
       $result = json_decode($result, true);  
        if ($result["data"][0]["value"] == ""){
            $userinfo2=explode(" ",$result["data"][0]["label"]);
            $b = ["code" => -1, 'msg' => $userinfo2[0]];
        }else{ 
          $courseList = $result["data"][0]["children"];
          foreach($courseList as $key => $value){ 
          $json_data[] = [ 
              'name' => $value['label'], 
              'id' => "", 
              ]; 
      } 
      $b = [ 'code' => 1, 'msg' => '查询成功', 'data' => $json_data ];
      }
    return $b;}
    //一流ck查课接口
	else if($type == "ylck"){
	   $addsalt=md5(mt_rand(0,999).time());
       $data = array("cid" => $noun, "userinfo"=>"$school $user $pass","hash"=>$addsalt);
       $yl_surl = $a["url"];
       $yl_url = "$yl_surl/api/ajax.php?act=getwk";
       $header = ["token:$token",];
       $result = post($yl_url,$data,$header); 
       $result = json_decode($result, true);  
        if ($result["code"] != 1){
            $b = ["code" => -1, 'msg' => $result["msg"]];
        }else{ 
          $courseList = $result["data"];
          foreach($courseList as $key => $value){ 
          $json_data[] = [ 
              'name' => $value['name'], 
              'id' => $value['id'], 
              ]; 
      } 
      $b = [ 'code' => 1, 'msg' => '查询成功', 'userName' => $result["userName"] , 'data' => $json_data];
      }
    return $b;}
    //King查课接口
    else if ($type == "king" || $type == "kingunit") {
        if($school=="")$school="自动识别";
        if($type=="king")$isunit=false;
        elseif($type=="kingunit")$isunit=true;
        $data = array(array("PlatformID" => $noun, "school" => $school, "username" => $user, "password" => $pass, "isUnit" => $isunit));
        $data=json_encode($data);
        $king_url = "http://api.chachawk.club/api/Order/GetClass";
        $cookie=$a['cookie'];
        $header= [
            "Authorization:Bearer ".$token,
            "Content-Type: application/json",
            ];
        $result = post($king_url, $data, $header);
        $result = json_decode($result, true);
        // var_dump($header);
        if(!$result){
            $b = ["code" => 9, 'msg' => "查课失败，请尝试二次查课！"];
        }elseif ($result["obj"][0]["data"] == null) {
            $b = ["code" => - 1, 'msg' => $result["obj"][0]["msg"]];
        } else {
            $courseList = $result["obj"][0]["data"];
            if($type=="kingunit"){
                foreach ($courseList as $key => $value) {
                    $title=$value['title'];
                    $unit=$value['children'];
                    for($i=0;count($unit)>$i;$i++){
                        $json_data[]=['name'=>$title."------".$unit[$i]['title']];
                    }
                }
            }else{
                foreach ($courseList as $key => $value) {
                    $json_data[] = ['name' => $value['title'], 'id' => $value['id'], 'userName' => $value["userName"]];
                }
            }
            $b = ['code' => 1, 'msg' => '查询成功', 'data' => $json_data];
        }
        return $b;
    }
    //老友查课
 else if ($type == "lyj") {
		$data = array("token" => $a["token"], "school" => $school, "account" => $user, "pass" => $pass, "platform" => $noun, "kcid" => $kcid);
		$lyj_rl = $a["url"];
		$lyj_url = "$lyj_rl/api/course.php";
		$result = get_url($lyj_url, $data);
		$result = json_decode($result, true);
		return $result;
	}
    //king ck查课接口
	else if($type == "kingck"){
       $data[] = array("PlatformID" => $noun, "school"=>$school, "username" => $user,"password" => $pass,"isUnit" => false); 
       $data=json_encode($data,true);
       $king_surl = $a["url"];
       $king_url = "$king_surl/api/Order/GetClass";
       $header = [
           "Content-Type:application/json;charset=utf-8",
           "Origin: {$a["url"]}",
	    	"x-requested-with:XMLHttpRequest",
           ];
           
       $result = get_url3($king_url,$data,$cookie,$header); 
       $result = json_decode($result, true);  
        if ($result["obj"][0]["data"] == null) 
      { $b = ["code" => -1, 'msg' => $result["obj"][0]["msg"]]; 
      }
           
      else
      { 
          $courseList = $result["obj"][0]["data"];
          foreach($courseList as $key => $value)
      { 
          $json_data[] = [ 
              
              'name' => $value['title'], 
              'id' => $value['id'], 
                          ]; 
      } 
      $b = [ 'code' => 1, 'msg' => '查询成功', 'data' => $json_data ]; 
                    
      }
    return $b;}
    //哥斯拉2.0查课接口 	
	else if($type == "gsl2.0"){
	    $data = array("Token" => $token,"school"=>$school,"username" => $user,"password" => $pass,"plat" => $noun, ); 
	    $gsl_surl = $a["url"];
	    $gsl_url = "$gsl_surl/api/unionApi/course";
        $result = get_url($gsl_url, $data); 
	    $result = json_decode($result, true);
	    if ($result["code"] == 200 ) {
	        $courseList = $result["data"];
                     foreach ($courseList as $key => $value) {
                         $json_data[] = [
                                'id' => $value['id'],
                                'name' => $value['name'],
                            ]; 
                             
                     }
                       $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ]; 
	    }else{
	         $b = ["code" => -1, 'msg' => $result["msg"]];
	    }
	    return $b;	}
//大雄学习平台查课接口 放在/Checkorder/ckjk.php 文件
if ($type == "daxiong") {
$data = array("uid" => $a["user"], "key" => $a["pass"], "school" => $school, "user" => $user, "pass" => $pass, "platform" => $noun, "kcid" => $kcid);
$dx_rl = $a["url"];
$dx_url = "$dx_rl/api.php?act=get";
$result = get_url($dx_url, $data);
$result = json_decode($result, true);
return $result;}
//29
if ($type == "29") {
$data = array("uid" => $a["user"], "key" => $a["pass"], "school" => $school, "user" => $user, "pass" => $pass, "platform" => $noun, "kcid" => $kcid);
$dx_rl = $a["url"];
$dx_url = "$dx_rl/api.php?act=get";
$result = get_url($dx_url, $data);
$result = json_decode($result, true);
return $result;}
	// 00查课接口 	
	else if($type == "00"){
	    $data = array("school"=>$school,"account" => $user,"password" => $pass,"token" => $token,"value" => $noun, ); 
	    $ll_surl = $a["url"];
	    $ll_url = "$ll_surl/querycourse";
        $result = get_url($ll_url, $data, $cookie); 
	    $result = json_decode($result, true);
	    
	 
	    if ($result["code"] != 0 ) {
	        $b = ["code" => -1, 'msg' => "信息错误或者重试"];
	    }else{
	         $courseList = $result["msg"]["data"];
                      
                     foreach ($courseList as $key => $value) {
                         
                         $json_data[] = [
                                'id' => "",
                                'name' => $value['coursename'],
                            ]; 
                             
                     }
                       $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ];  
	    }
	    return $b;	}
	//捐赠接口
    else if($type == "jz"){
        $data = array("school_name"=>$school,"username" => $user,"password" => $pass ); 
	    $jz_surl = $a["url"];
	    $jz_url = "$jz_surl/api/$noun";
        $result = get_url($jz_url, $data, $cookie);
	    $result = json_decode($result, true);  
	    $code = $result["code"];
	    $resultd = explode("\n",$result["data"]);
       if ($code != 0 ) {
	        $b = ["code" => -1, 'msg' => "信息错误或者重试"];
	    }else{
	         $courseList = $resultd;
                     foreach ($courseList as $key => $value) {
                         $json_data[] = [
                                
                                'name' => $value ,
                            ]; 
                     }
                       $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ];  
	    }
	    return $b;	} 
	//职教云官方
	else if($type == "zjygf"){
       $url = $_SERVER['HTTP_HOST'] ;
	   $gf_url = "http://$url/Checkorder/zjygf.php?py=1&school=$school&user123456=$user&pwd123456=$pass";
	   $result=file_get_contents($gf_url); 
	   $result = json_decode($result, true);
	   return $result;
     	}
	//mooc官方
	else if($type == "moocgf"){
       $url = $_SERVER['HTTP_HOST'] ;
	   $gf_url = "http://$url/Checkorder/zjygf.php?py=2&school=$school&user123456=$user&pwd123456=$pass";
	   $result=file_get_contents($gf_url); 
	   $result = json_decode($result, true);
	   return $result;
     	}  
    //资源库官方
	else if($type == "zykgf"){
       $url = $_SERVER['HTTP_HOST'] ;
	   $gf_url = "http://$url/Checkorder/zjygf.php?py=3&school=$school&user123456=$user&pwd123456=$pass";
	   $result=file_get_contents($gf_url); 
	   $result = json_decode($result, true);
	   return $result;
     	} 
    //学习通官方查课接口
	else if($type == "xxtgf"){
       $url = $_SERVER['HTTP_HOST'] ;
	   $gf_url = "http://$url/Checkorder/xxtgf.php?school=$school&name=$user&pwd=$pass";
	   $result=file_get_contents($gf_url); 
	   $result = json_decode($result, true);
	   return $result;
     	}
     	//短信xz
    else if($type == "dx"){
        $data = array("username" => $user ); 
	    $jz_surl = $a["url"];
	    $jz_url = "$jz_surl/api/$noun";
        $result = get_url($jz_url, $data, $cookie);
	    $result = json_decode($result, true);  
	    $code = $result["code"];
	    $resultd = explode("\n",$result["data"]);
       if ($code != 0 ) {
	        $b = ["code" => -1, 'msg' => "信息错误或者重试"];
	    }else{
	         $courseList = $resultd;
                     foreach ($courseList as $key => $value  ) {
                         $value='轰炸';
                         
                         $json_data[] = [
                                'id'=>"$user",
                                'name' => $value,
                                
                            ]; 
                           
                     }
                       $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ];  
	    }
	    return $b;	} 
	    	//ppt代
    else if($type == "ppt"){
        $data = array("username" => $user,"password" => $pass  ); 
	    $jz_surl = $a["url"];
	    $jz_url = "$jz_surl/api/$noun";
        $result = get_url($jz_url, $data, $cookie);
	    $result = json_decode($result, true);  
	    $code = $result["code"];
	    $resultd = explode("\n",$result["data"]);
       if (!preg_match('/^\w+@qq\.com$/', $pass)) {
	        $b = ["code" => -1, 'msg' => "填写的邮箱真的正确吗？"];
	    }else{
	         $courseList = $resultd;
                     foreach ($courseList as $key => $value  ) {
                         $value='发送的邮箱';
                         
                         $json_data[] = [
                                'id'=>"$pass",
                                'name' => $value,
                                
                            ]; 
                           
                     }
                       $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ];  
	    }
	    return $b;	} 
	    //暴力破解冷门网课
    else if($type == "wangke"){
        $data = array("school"=>$school,"username" => $user,"password" => $pass ); 
	    $jz_surl = $a["url"];
	    $jz_url = "$jz_surl/api/$noun";
        $result = get_url($jz_url, $data, $cookie);
	    $result = json_decode($result, true);  
	    $code = $result["code"];
	    $resultd = explode("\n",$result["data"]);
       if (!filter_var($school, FILTER_VALIDATE_URL)) {
	        $b = [
	            "code" => -1, 
	            'msg' => "需要破解的网址确定正确吗？"
	            ];
	    }else{
	         $courseList = $resultd;
                     foreach ($courseList as $key => $value  ) {
                         $value='暴力破解冷门网课网址';
                         
                         $json_data[] = [
                                'id'=>"$school",
                                'name' => $value,
                                
                            ]; 
                           
                     }
                       $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ];  
	    }
	    return $b;	} 
	    //ayck查课接口
    else if($type == "ayck"){
        $data = array("platform" => $noun, "school"=>$school, "account" => $user,"pwd" => $pass); 
        $ay_surl = $a["url"];
        $result = post($ay_surl, $data,); 
        $result = json_decode($result, true);
         
        if ($result["code"] != 0 ) {
                        $b = ["code" => -1, 'msg' => "信息错误或者重试"];
                    }else{
                     $courseList = $result["data"]; 
                      
                     foreach ($courseList as $key => $value) {
                         
                         $json_data[] = [
                                'id' => "",
                                'name' => $value['name'],
                            ]; 
                             
                     }
                       $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ];  
                  
        }
  return $b;}
    // 哆啦a梦接口
    else if($type == "dlam"){
        $sign = md5($noun.$user." ".$pass."|"."sign2022");
        $data = "coursename=$noun&accont=$user+$pass%7C&sign=$sign&warning=%E8%AF%B7%E4%B8%8D%E8%A6%81%E5%AF%B9%E6%9C%AC%E6%9D%A1%E6%95%B0%E6%8D%AE%E8%BF%9B%E8%A1%8C%E9%87%8D%E6%94%BE%2C%E4%BF%AE%E6%94%B9%2C%E5%90%8E%E6%9E%9C%E8%87%AA%E8%B4%9F%EF%BC%81";
        $dlam_surl = $a["url"];
        $dlam_url = "$dlam_surl/admin/sysUser/chake";
       // 在后台设置接口里面填cookie
        $header = ["Cookie:$cookie","Content-Type:application/x-www-form-urlencoded","User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"];
        $result = post($dlam_url, $data, $header);
        $result = json_decode($result, true);
        if($result["code"]==200){
             $result =json_decode($result['message'],true);
           foreach ($result[0]['children'] as $key => $value) {
                         $json_data[] = [
                                'id' => $value['id'],
                                'name' => $value['title'],
                            ]; 
                     }
                     $b  = [
                        'code' => 0,
                        'msg' => '查询成功',
                        'data' => $json_data
                    ];  
        }
  return $b;}
	else {
    print_r("没有了,文件ckjk.php,可能故障：参数缺少，比如平台名错误！！！");die;
	}
}
 

?>